#include <QtGui/QApplication>
#include "mainwindow.h"
#include <QDebug>
#include <QSymbianEvent>
#include <QWebFrame>

#ifdef Q_OS_SYMBIAN
#include <W32STD.H>
#include <aknappui.h>
#include <avkon.rsg>
#endif

class HybridFWApplication : public QApplication
{
public:

    HybridFWApplication(int & argc, char ** argv ) : QApplication(argc, argv) {}

    
#ifdef Q_OS_SYMBIAN
    bool symbianEventFilter ( const QSymbianEvent *event )
    {
    	// TODO: Refactor this to use signals. 
        if(event && event->windowServerEvent() && m_webFrame)
        {
            if( event->windowServerEvent()->Type() == EEventFocusLost)
                m_webFrame->evaluateJavaScript("widgetOnHide()");
            else if( event->windowServerEvent()->Type() == EEventFocusGained)
                m_webFrame->evaluateJavaScript("widgetOnShow()");
        }

        return false;
    }
#endif

    void setWebFrame(QWebFrame *webFrame) { m_webFrame = webFrame; }
private:
    QWebFrame *m_webFrame;
};

int main(int argc, char *argv[])
{
    HybridFWApplication a(argc, argv);
    
#ifdef Q_OS_SYMBIAN
    CEikStatusPane* statusPane = STATIC_CAST( CAknAppUi*, CEikonEnv::Static()->EikAppUi())->StatusPane();
    statusPane->SwitchLayoutL(R_AVKON_STATUS_PANE_LAYOUT_EMPTY);
#endif
    
    MainWindow w;
    a.setWebFrame(w.webFrame());

    w.showMaximized();
    return a.exec();
}
